﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Text;
using System.Data;

namespace IHISCETeim.Web.MachineSys.FXModel
{
    public partial class AreaManagerSJZYList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "AreaManagerSJZYList";
            }


        }
        protected string AliasName
        {
            get
            {
                return GetRequestValue<string>("AliasName", "");

            }
        }
        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return GetRequestValue<string>("orderField", "OverdueNumber");
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return GetRequestValue<string>("orderDirection", "desc");
            }
        }
        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection + " ,AliasName desc");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }

        private void DataBind()
        {
            string agentsqltemp = SAreaManagerAgentController.GetMyAgentSqlWhere();          
            string wheresql = string.Format(" AliasName in ({0})", agentsqltemp);

            DataTable dtc = null;

            dtc = FXSJZYController.FXSJZYAgentGetByWhere(wheresql);
            //sumdt = dtc[1];
            this.rpMenu0.DataSource = dtc;
            this.rpMenu0.DataBind();

            dtc = FXSJZYController.FXSJZYDetailGetPagination(GetWhereSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            // sumdt = dtc[1];
            this.rpMenu1.DataSource = dtc;
            this.rpMenu1.DataBind();
            
        }

        protected string GetWhereSql()
        {
            string agentsqltemp = SAreaManagerAgentController.GetMyAgentSqlWhere();
            if (string.IsNullOrEmpty(agentsqltemp))
                return "1<>1";
            string wheresql = string.Format(" AliasName in ({0})", agentsqltemp);
           

            if (!AliasName.IsEmptyOrNull())
            {
                string aliasNamesql = QueryOperatorsEnumHelper.ConvertCommonOperator("AliasName", QueryOperatorsEnum.等于, AliasName);
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = aliasNamesql;
                else
                    wheresql += " and " + aliasNamesql;
            }

            return wheresql;



        }

        protected string GetColumnTitle(int index)
        {
            int day = DateTime.Now.Day;
            List<string> columns = new List<string>();

            if (day <= 18)
            {
                columns.Add(DateTime.Now.AddMonths(-3).Month.ToString());
                columns.Add(DateTime.Now.AddMonths(-2).Month.ToString());
                columns.Add(DateTime.Now.AddMonths(-1).Month.ToString());
            }
            else
            {
                columns.Add(DateTime.Now.AddMonths(-2).Month.ToString());
                columns.Add(DateTime.Now.AddMonths(-1).Month.ToString());
                columns.Add(DateTime.Now.Month.ToString());
            }

            return columns[index - 1] + "月逾期租金";
        }
    }
}